//
//  DimmingPresentationController.swift
//  StoreSearch
//
//  Created by cygarm on 15/12/26.
//  Copyright © 2015年 cygarm. All rights reserved.
//

import Foundation
import UIKit

class DimmingPresentationController: UIPresentationController {
	lazy var dimmingView = GradientView(frame: CGRect.zero)
	
	override func shouldRemovePresentersView() -> Bool {
		return false
	}
	
	override func presentationTransitionWillBegin() {
		dimmingView.frame = (containerView?.bounds)!
		containerView?.insertSubview(dimmingView, atIndex: 0)
		
		dimmingView.alpha = 0
		if let transitionCoordinator = presentedViewController.transitionCoordinator() {
			transitionCoordinator.animateAlongsideTransition({ (_) -> Void in
				self.dimmingView.alpha = 1
			}, completion: nil)
		}
	}
	
	override func dismissalTransitionWillBegin() {
		if let transitionCoordinator = presentedViewController.transitionCoordinator() {
			transitionCoordinator.animateAlongsideTransition({ (_) -> Void in
				self.dimmingView.alpha = 0
			}, completion: nil)
		}
	}
}